package com.tjhk.netty.test;

import com.tjhk.netty.codec.MessageEncoder;
import com.tjhk.netty.test.model.MyMessage;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.nio.charset.StandardCharsets;

public class JTMessageEncoder implements MessageEncoder<MyMessage> {

    @Override
    public ByteBuf encode(MyMessage message) {
        StringBuilder msg = new StringBuilder();
        msg.append(message.getBody());
        byte[] bytes = msg.toString().getBytes(StandardCharsets.UTF_8);
        return Unpooled.wrappedBuffer(bytes);
    }
}
